package com.jit.BluetoothKey.entity;

import android.bluetooth.BluetoothGattCharacteristic;

import com.clj.fastble.data.BleDevice;

/**
 * Created by Administrator on 2018/2/1.
 * MVVM  下单例模式状态实体类 用于多个fragment  调用
 */

public class BleControllerHelper {
    public static BleControllerHelper instance = null;
    private boolean bleUseful = false;  //蓝牙是否可以标识
    private BluetoothGattCharacteristic writeBleCharacter;// 蓝牙写特征
    private BluetoothGattCharacteristic readBleCharacter; // 蓝牙读特征
    private BleDevice bleDevice; // 蓝牙操作对象
    private BleStatesChangeListner bleStatesChangeListner;


    private BleControllerHelper() {
    }

    public static BleControllerHelper getInstance() {
        if (instance == null) {
            synchronized (BleControllerHelper.class) {
                if (instance == null) {
                    instance = new BleControllerHelper();
                }
            }
        }
        return instance;
    }

    public boolean isBleUseful() {
        return bleUseful;
    }

    public void setBleUseful(boolean bleUseful) {
        this.bleUseful = bleUseful;
        if (bleUseful&&bleStatesChangeListner!=null){
            bleStatesChangeListner.bleEnable();
        }else if (!bleUseful&&bleStatesChangeListner!=null){
            bleStatesChangeListner.bleUnenable();
        }

    }

    public BluetoothGattCharacteristic getWriteBleCharacter() {
        return writeBleCharacter;
    }


    public BluetoothGattCharacteristic getReadBleCharacter() {
        return readBleCharacter;
    }

    public void setWriteBleCharacter(BluetoothGattCharacteristic writeBleCharacter) {
        this.writeBleCharacter = writeBleCharacter;
    }

    public void setReadBleCharacter(BluetoothGattCharacteristic readBleCharacter) {
        this.readBleCharacter = readBleCharacter;
    }

    public BleDevice getBleDevice() {
        return bleDevice;
    }

    public void setBleDevice(BleDevice bleDevice) {
        this.bleDevice = bleDevice;
    }

    public void setBleStatesChangeListner(BleStatesChangeListner bleStatesChangeListner){
        this.bleStatesChangeListner = bleStatesChangeListner;
    }

    public interface BleStatesChangeListner{
        void bleEnable();
        void bleUnenable();
    }

}
